@extends('admin.layouts.base')
@section('content')
    <div>
        <el-col :span="4">
            <a href="{{route('admin.goods.create')}}">
                <el-button type="text" size="small">添加</el-button>
            </a>
        </el-col>
        <el-col :span="24">
            <el-table :data="tableData" style="width: 100%">
                <el-table-column prop="goods_id" label="商品id"></el-table-column>
                <el-table-column prop="name" label="标题"></el-table-column>
                <el-table-column prop="category_name" label="分类"></el-table-column>
                <el-table-column prop="price" label="价格"></el-table-column>
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <el-button type="text" size="small">
                            <a :href="getEditUrl(scope.row.goods_id)">修改</a>
                        </el-button>
                        <el-button type="text" size="small" @click="handleDelete(scope.row.goods_id)">
                            删除
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
            <el-pagination background layout="prev, pager, next" :total="total" @current-change="handlePageChange"
                           :page-size="15"></el-pagination>
        </el-col>
    </div>
@endsection
@section('scripts')
    <script>
        new Vue({
            el: '#app',
            data: function () {
                return {
                    tableData: [],
                    visible: false,
                    filter: {
                        page: 1,
                    },
                    total: 0,
                    form: {
                        name: '',
                        // region: '',
                        // date1: '',
                        // date2: '',
                        // delivery: false,
                        attrs: [],
                        // resource: '',
                        // desc: ''
                    }
                }
            },
            methods: {
                handleDelete(goodsId) {
                    this.$confirm('此操作将永久删除该商品, 是否继续?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        let self = this;
                        axios.post('{{route('admin.goods.destroy')}}', {'goods_id': goodsId}).then(function (res) {
                            self.$message(res.data.msg);
                            self.getLists();
                        });

                    }).catch(() => {
                    });
                },
                addDomain() {
                    this.form.attrs.push({
                        color: '',
                        size: '',
                        num: '',
                        key: Date.now()
                    });
                },
                getLists() {
                    let self = this;
                    axios.post('{{route('admin.goods.list')}}', this.filter).then(function (res) {
                        if (res.data.status !== 0) {
                            self.$message('s');
                        } else {

                            self.tableData = res.data.data.data;
                            self.filter.page = res.data.data.current_page;
                            self.total = res.data.data.total;
                        }
                    })
                },
                handlePageChange(e) {
                    this.filter.page = e;
                    this.getLists();
                },
                handleShip(row) {

                    let self = this;
                    axios.post('{{route('admin.order.ship')}}', {
                        order_id: row.order_id
                    }).then(function (res) {
                        if (res.data.status !== 0) {
                            self.$message.error(res.data.msg);
                        } else {
                            self.$message('操作成功');
                            self.getLists();
                        }
                    })
                },
                getOrderStateCn(state) {
                    if (state === 1) {
                        return '待支付';
                    }
                    if (state === 2) {
                        return '待发货';
                    }
                    if (state === 3) {
                        return '待收货';
                    }
                    if (state === 4) {
                        return '已完成';
                    }
                },
                getEditUrl(id) {
                    let url = '{{route('admin.goods.create')}}';
                    return url + '?goods_id=' + id;
                }
            },
            mounted() {
                this.getLists();
            }
        })
    </script>
@endsection
